package et.six.eta.View.ViewPager;

import android.content.Context;
import android.content.Intent;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;

import java.util.ArrayList;
import java.util.List;

import et.six.eta.Adapter.EatViewPagerAdapter;
import et.six.eta.R;
import et.six.eta.View.LoginActivity;

public class EatViewPager extends RelativeLayout {
    Button button;
    private ViewPager myviewpager;
    private List<View> mylist = new ArrayList<>();
    private TransforView mytrans;
    private int[] mylayouts = new int[]{R.layout.viewpager_view_one, R.layout.viewpager_view_two,
            R.layout.viewpager_view_three, R.layout.viewpager_view_four
    };
    private EatViewPagerAdapter eatViewPagerAdapter;


    public EatViewPager(Context context) {
        super(context);
        init();
    }

    public EatViewPager(Context context, AttributeSet attributes) {
        super(context, attributes);
        init();
    }

    private void init() {

        inflate(getContext(), R.layout.layout_eat_viewpager, this);

        {
            /**初始化四个界面*/
            for (int i = 0; i < mylayouts.length; i++) {
                View view = View.inflate(getContext(), mylayouts[i], null);
                mylist.add(view);
            }
        }
        myviewpager = this.findViewById(R.id.viewpager);
        mytrans = this.findViewById(R.id.transfor_view);
        button = mylist.get(3).findViewById(R.id.start_four_bt);

        button.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                getContext().startActivity(new Intent(getContext(), LoginActivity.class));

            }
        });

        eatViewPagerAdapter = new EatViewPagerAdapter(mylist, getContext());
        myviewpager.setAdapter(eatViewPagerAdapter);
        myviewpager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int i, float v, int i1) {
                mytrans.transfor(i, v, i1);

            }

            @Override
            public void onPageSelected(int i) {

            }

            @Override
            public void onPageScrollStateChanged(int i) {

            }
        });


    }
}
